﻿using System;
namespace Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="toimik_jada_item", Namespace="http://producers.taitis.xtee.riik.ee/producer/taitis", Target=typeof(ToimikJadaItem))]
    public class ToimikJadaItemSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IToimikJadaItem clazz;
        
        public ToimikJadaItemSerializer(IToimikJadaItem clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("toimiku_number");
            if (clazz.ToimikuNumber!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ToimikuNumber))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ToimikuNumber");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("menetlusseisund");
            if (clazz.Menetlusseisund!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Menetlusseisund))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Menetlusseisund");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("lahendiliik");
            if (clazz.Lahendiliik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Lahendiliik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Lahendiliik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("lahendi_number");
            if (clazz.LahendiNumber!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LahendiNumber))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : LahendiNumber");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("lahendikpv");
            if (clazz.Lahendikpv!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Lahendikpv))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Lahendikpv");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("lahendi_tegija");
            if (clazz.LahendiTegija!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LahendiTegija))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : LahendiTegija");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("nouete_kogusuurus");
            if (clazz.NoueteKogusuurus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.NoueteKogusuurus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : NoueteKogusuurus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("taituri_eesnimi");
            if (clazz.TaituriEesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TaituriEesnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TaituriEesnimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("taituri_perekonnanimi");
            if (clazz.TaituriPerekonnanimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TaituriPerekonnanimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TaituriPerekonnanimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("taituri_aadress");
            if (clazz.TaituriAadress!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TaituriAadress))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TaituriAadress");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("taituri_telefon");
            if (clazz.TaituriTelefon!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TaituriTelefon))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TaituriTelefon");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("taituri_faks");
            if (clazz.TaituriFaks!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TaituriFaks))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TaituriFaks");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("taituri_mail");
            if (clazz.TaituriMail!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TaituriMail))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TaituriMail");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("noue_jada");
            if (clazz.NoueJada!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("noue_jada_item", "http://producers.taitis.xtee.riik.ee/producer/taitis", clazz.NoueJada.Count);
                for (int x = 0; ((clazz.NoueJada != null) 
                            && (x < clazz.NoueJada.Count)); x = (x + 1)) {
                    if (clazz.NoueJada[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaNoueJada = this.GetMetaData(clazz.NoueJada[x]);
                        Writer.WriteTypeAttribute(metaNoueJada.TypeQualifiedName.Namespace, metaNoueJada.TypeQualifiedName.Name);
                        metaNoueJada.NewSerializer(clazz.NoueJada[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : NoueJada");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "toimiku_number")) {
                goto toimiku_number;
            }
            else {
                if ((Reader.LocalName == "menetlusseisund")) {
                    goto menetlusseisund;
                }
                else {
                    if ((Reader.LocalName == "lahendiliik")) {
                        goto lahendiliik;
                    }
                    else {
                        if ((Reader.LocalName == "lahendi_number")) {
                            goto lahendi_number;
                        }
                        else {
                            if ((Reader.LocalName == "lahendikpv")) {
                                goto lahendikpv;
                            }
                            else {
                                if ((Reader.LocalName == "lahendi_tegija")) {
                                    goto lahendi_tegija;
                                }
                                else {
                                    if ((Reader.LocalName == "nouete_kogusuurus")) {
                                        goto nouete_kogusuurus;
                                    }
                                    else {
                                        if ((Reader.LocalName == "taituri_eesnimi")) {
                                            goto taituri_eesnimi;
                                        }
                                        else {
                                            if ((Reader.LocalName == "taituri_perekonnanimi")) {
                                                goto taituri_perekonnanimi;
                                            }
                                            else {
                                                if ((Reader.LocalName == "taituri_aadress")) {
                                                    goto taituri_aadress;
                                                }
                                                else {
                                                    if ((Reader.LocalName == "taituri_telefon")) {
                                                        goto taituri_telefon;
                                                    }
                                                    else {
                                                        if ((Reader.LocalName == "taituri_faks")) {
                                                            goto taituri_faks;
                                                        }
                                                        else {
                                                            if ((Reader.LocalName == "taituri_mail")) {
                                                                goto taituri_mail;
                                                            }
                                                            else {
                                                                if ((Reader.LocalName == "noue_jada")) {
                                                                    goto noue_jada;
                                                                }
                                                                else {
                                                                    return;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        toimiku_number:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>toimiku_number");
            }
            clazz.ToimikuNumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("toimiku_number")).Value;
            goto START;
        menetlusseisund:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>menetlusseisund");
            }
            clazz.Menetlusseisund = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("menetlusseisund")).Value;
            goto START;
        lahendiliik:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>lahendiliik");
            }
            clazz.Lahendiliik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("lahendiliik")).Value;
            goto START;
        lahendi_number:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>lahendi_number");
            }
            clazz.LahendiNumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("lahendi_number")).Value;
            goto START;
        lahendikpv:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>lahendikpv");
            }
            clazz.Lahendikpv = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("lahendikpv")).Value;
            goto START;
        lahendi_tegija:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>lahendi_tegija");
            }
            clazz.LahendiTegija = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("lahendi_tegija")).Value;
            goto START;
        nouete_kogusuurus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>nouete_kogusuurus");
            }
            clazz.NoueteKogusuurus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nouete_kogusuurus")).Value;
            goto START;
        taituri_eesnimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>taituri_eesnimi");
            }
            clazz.TaituriEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("taituri_eesnimi")).Value;
            goto START;
        taituri_perekonnanimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>taituri_perekonnanimi");
            }
            clazz.TaituriPerekonnanimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("taituri_perekonnanimi")).Value;
            goto START;
        taituri_aadress:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>taituri_aadress");
            }
            clazz.TaituriAadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("taituri_aadress")).Value;
            goto START;
        taituri_telefon:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>taituri_telefon");
            }
            clazz.TaituriTelefon = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("taituri_telefon")).Value;
            goto START;
        taituri_faks:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>taituri_faks");
            }
            clazz.TaituriFaks = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("taituri_faks")).Value;
            goto START;
        taituri_mail:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>taituri_mail");
            }
            clazz.TaituriMail = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("taituri_mail")).Value;
            goto START;
        noue_jada:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik_jada_item>noue_jada");
            }
            clazz.NoueJada = new System.Collections.Generic.List<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.INoueJadaItem>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("noue_jada");
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "item")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>toimik_jada_item>noue_jada>item");
                    }
                    global::Xtee.Core.SerializationMetadata metaNoueJada = this.GetMetaData<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.INoueJadaItem>(Reader, "noue_jada_item", "http://producers.taitis.xtee.riik.ee/producer/taitis");
                    global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.INoueJadaItem item = metaNoueJada.NewEntity<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.INoueJadaItem>();
                    clazz.NoueJada.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("item");
                        metaNoueJada.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
    }
}
